using Model.Core.DbContexts;
using Microsoft.OpenApi.Models;
using NLog.Web;

namespace RobotWebApiService
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.

            builder.WebHost.UseUrls("http://0.0.0.0:5000"); // 添加此行
            // 添加数据库上下文
            builder.Services.AddDbContext<MyDbContext>();
            builder.Configuration.AddJsonFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configures/robotbase.json"));

            // 添加控制器
            builder.Services.AddControllers();

            // 添加NLog日志服务
            builder.Services.AddLogging(loggingBuilder =>
            {
               // loggingBuilder.ClearProviders();
                loggingBuilder.SetMinimumLevel(LogLevel.Information);
            });

            // 加载NLog配置
            //NLogBuilder.ConfigureNLog("nlog.config");

            // 添加 Swagger 服务
            builder.Services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo { Title = "RobotWebApiService", Version = "v1" });
            });
            var app = builder.Build();

            app.UseRouting();

            // 开发环境使用 Swagger
            //  if (app.Environment.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI();
            }
            //// 使用NLog日志中间件
            //app.UseNLog();

            app.UseHttpsRedirection();

 

            app.UseAuthorization();

            app.MapControllers();

            app.Run();
        }
    }
}
